package com.system.service.impl;

import com.system.dao.UpFileQuestionDao;
import com.system.service.UpFileQuestionService;
import com.system.util.Excel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("upFileQuestionService")
public class UpFileQuestionServiceImpl implements UpFileQuestionService {

    @Autowired
    UpFileQuestionDao upFileQuestionDao;

    @Override
    public String InputExcel(InputStream is, String originalFilename) {
        Map<String,Object> ginsengMap = new HashMap<String,Object>();
        List<ArrayList<Object>> list;
        if (originalFilename.endsWith(".xls")) {
            list = Excel.readExcel2003(is);
        } else {
            list = Excel.readExcel2007(is);
        }
        for (int i=0,j=list.size();i<j;i++){
            List<Object> row = list.get(i);
            ginsengMap.put("title", row.get(0).toString());
            ginsengMap.put("question_type", row.get(1).toString());
            ginsengMap.put("knowledge", row.get(2).toString());
            ginsengMap.put("intellectual_filed", row.get(3).toString());
            ginsengMap.put("attrA", row.get(4).toString());
            ginsengMap.put("attrB", row.get(5).toString());
            ginsengMap.put("attrC", row.get(6).toString());
            ginsengMap.put("attrD", row.get(7).toString());
            ginsengMap.put("answer", row.get(8).toString());
            ginsengMap.put("analysis", row.get(9).toString());
            upFileQuestionDao.InputExcel(ginsengMap);
        }
        return "success";
    }

}
